package standalone;

import java.util.HashMap;

public class Klasa {
	
	public static final int NO_ACCESS = 0;
	public static final int ACCESS = 1;
	
	public static int totalCounts;
	private int indentifier;
	private int count;
	//pierwszy Integer oznacza numer RESOURCE np 22.
	private HashMap<Integer, Category> wspolczynniki = new HashMap<Integer,Category>();
	
	public Klasa(int ind){
		indentifier = ind;
	}
	
	public int hashCode(){
		return indentifier;
	}
	
	public boolean equals(Object o){
		if (o instanceof Klasa){
			Klasa kl = (Klasa)o;
			if(kl.indentifier == indentifier)
				return true;
		}else if(o instanceof Integer){
			Integer i = (Integer)o;
			if(i.intValue() == indentifier)
				return true;
		}
			
		return false;
	}
	
	public void learn(String[] values){
		count++;
		totalCounts++;
		//wartosc RESOURCE
		int i = Integer.valueOf(values[1]);
		Category wsp = wspolczynniki.get(i);
		if(wsp == null){
			wsp = new Category();
			wspolczynniki.put(i, wsp);
		}
		wsp.saveRow(values);
	}

	
	public double predict(Integer[] values){
		Category wsp;
		//zamiast getPrior
		double val = 0.0;
		//RESOURCE
		wsp = wspolczynniki.get(values[1]);
		Integer c;
		if(wsp != null)
			count = wsp.getCounter();
		else
			count = 1;
		for(int i = 2; i < values.length; i++){
			//jezeli c = 0, to dodamy 1 i count  = 0 to tez dodamy jeden, wyjdze nam 100%
			//ten smooting jest kiepiski
			if(wsp != null){
				c = wsp.getCount(i, values[i]);
				if(c == null)
					c = 0;
			}
			else
				c = 0;
			val += (double)c/count;
			
		}
		//7.0 bo tyle jest kolumn ktore bierzemy pod uwage
		val /= 7.0;
		return val;
	}
	
	

	public void setCount(int count) {
		this.count = count;
	}
	
	public double getPrior(){
		double d = (double)count/totalCounts;
		return d;
	}
	
	
}
